#!-*- encoding:utf8 -*-
from django.db import models
from django.contrib.auth.models import User
from newosmp.define import *
from newosmp.monitor.models import Monitor
from newosmp.strategy.models import Strategy
from newosmp.group.models import Group


# Create your models here.
#class Strategy(models.Model):
#    tpl = models.CharField(max_length=20, choices= CH_TPL) #
#    value = models.CharField(max_length=255)               #
#    detail = models.CharField(max_length=255)              #

class AlertGroup(models.Model):
    gname = models.CharField(max_length=20)
    detail = models.CharField(max_length=255)

class AlertReceive(models.Model):
#    gid = models.ForeignKey(AlertGroup)
    gid = models.ForeignKey(Group)
    uid = models.ForeignKey(User)
    mode = models.CharField(max_length=4)

class AlertBing(models.Model):
    mid = models.ForeignKey(Monitor)
    sid = models.ForeignKey(Strategy)
    gid = models.ForeignKey(Group)

class Alert(models.Model):
    mid = models.ForeignKey(Monitor)
    type =  models.CharField(max_length=1)
    detail = models.CharField(max_length=50)
    timestamp = models.DateTimeField(auto_now_add = True)
    downtime = models.IntegerField(blank=True)
    rtype = models.CharField(max_length=10, blank=True)
    reason = models.TextField(blank=True)
    uid = models.CharField(max_length=20, blank=True)

    def __unicode__(self):
        return u"mid:%s" % (self.mid)

    def __str__(self):
        return "mid:%s" % (self.mid)
